﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HR.ProjectX.BLL.Messaging;
using HR.ProjectX.DAL.UnitOfWork;
using HR.ProjectX.DAL.Repositories;
using HR.ProjectX.BLL.ViewModels;
using HR.ProjectX.Models.Entities.Vehicles;

namespace HR.ProjectX.BLL.Services.ManufacturerService
{
    public class ManufacturerService : IManufacturerService
    {
        private readonly IUnitOfWork _uow;
        private readonly IManufacturerRepository _manufacturerRepository;

        public ManufacturerService(IUnitOfWork uow,
                                   IManufacturerRepository manufacturerRepository)
        {
            _uow = uow;
            _manufacturerRepository = manufacturerRepository;
        }

        public GetAllManufacturersResponse GetAllManufacturers()
        {
            IList<Manufacturer> manufacturers = _manufacturerRepository.FindAll();
            IList<ManufacturerView> viewModels = new List<ManufacturerView>();

            // Ik doe de mapping zelf ipv Automapper.
            foreach (Manufacturer manufacturer in manufacturers)
            {
                ManufacturerView viewModel = new ManufacturerView();
                viewModel.ManufacturerName = manufacturer.ManufacturerName;
                viewModel.ManufacturerDetails = manufacturer.ManufacturerDetails;

                viewModels.Add(viewModel);
            }

            GetAllManufacturersResponse response = new GetAllManufacturersResponse();
            response.Manufacturers = viewModels;

            return response;
        }
    }
}
